package de.tum.in.eist.poll.client.gui;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ButtonBase;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;

import de.tum.in.eist.poll.shared.User;

public class Headline extends HorizontalPanel {
	
	private Button notifyButton;
	private Button currentWeekButton;
	private Button lastWeekButton;
	private Button semesterButton;
	private PushButton overAllButton;
	private Button createLectureButton;
	private PushButton logoutButton;
	private User user;
	
	public Headline(User user) {
		this.user = user;
		init();
		addContent();
		
		System.out.println("user has " + user.getNotifications().size() + " notifications");
	}

	private void addContent() {
		add(notifyButton);
		add(currentWeekButton);
		add(lastWeekButton);
		add(semesterButton);
		add(overAllButton);
		
//		if (user.isLecturer())
//			add(createLectureButton);
		
		add(logoutButton);
	}

	private void init() {
		// Notification
		notifyButton = new Button(user.getNotifications().size() + "");
		// This week
		currentWeekButton = new Button("This week");
		// last two weeks
		lastWeekButton = new Button("Last week");
		// Select range
		semesterButton = new Button("Semester");
		// Over-all statistic
		overAllButton = new PushButton(new Image("/images/StatButton.png"));
		// Create Lecture
		createLectureButton = new Button("Create Lecture");
		// Logout
		logoutButton = new PushButton(new Image("/images/LogOutButton.png"));
		
		setVerticalAlignment(ALIGN_MIDDLE);
		
		// Add Styles
		addStyleName("headlineForm");
		notifyButton.addStyleName("headlineButton");
		notifyButton.addStyleName("notificationsButton");
		overAllButton.addStyleName("headlineButton");
		currentWeekButton.addStyleName("headlineButton");
		lastWeekButton.addStyleName("headlineButton");
		semesterButton.addStyleName("headlineButton");
		createLectureButton.addStyleName("headlineButton");
		logoutButton.addStyleName("headlineButton");
	}

	/**
	 * Add the active style name to the committed button.
	 * @param button
	 */
	public void addActiveStyleNameTo(ButtonBase button) {
		button.addStyleName("headlineButtonActive");
	}
	
	/**
	 * Remove the active style name from the committed button.
	 * @param button
	 */
	public void removeActiveStyleNameFrom(ButtonBase button) {
		button.removeStyleName("headlineButtonActive");
	}

	public void updateNotificationNumber() {
		notifyButton.setText(user.getNotifications().size() + "");
	}
	
	public Button getNotifyButton() {
		return notifyButton;
	}

	public Button getCurrentWeekButton() {
		return currentWeekButton;
	}

	public Button getLastWeekButton() {
		return lastWeekButton;
	}

	public Button getSemesterButton() {
		return semesterButton;
	}

	public PushButton getOverAllButton() {
		return overAllButton;
	}

	public Button getCreateLectureButton() {
		return createLectureButton;
	}
	
	public PushButton getLogoutButton() {
		return logoutButton;
	}
}
